package com.visec.hdy.hadoop.analysis;

import java.lang.reflect.Field;

import org.apache.log4j.Logger;

import com.visec.hdy.hadoop.standard.Analysis;

/**
 * 默认解析类
 * 
 * @author hdy
 *
 * @param <V>
 */
public abstract class DefaultAnalysisImpl<K, V, R> implements Analysis<K, V, R> {
	final Logger l = Logger.getLogger(DefaultAnalysisImpl.class);
	protected String key;

	public DefaultAnalysisImpl(String key) {
		this.key = key;
	}

	/**
	 * 反射获取主键值
	 * 
	 * @param value
	 * @return
	 */
	public Object reflexField(String field, V value) {
		Field f;
		try {
			f = value.getClass().getDeclaredField(field);
			f.setAccessible(true);
			return f.get(value);
		} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
			l.error("", e);
		}
		return null;
	}
}
